home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / components / pyabout.py < prev    next >
Encoding:
Python Source  |  2006-06-19  |  1.9 KB  |  69 lines

  1. # about:python, originally by Alex Badea
  2. from xpcom import components, verbose
  3. import sys, os
  4. import platform
  5.  
  6. def getAbout():
  7.     # Generate it each time so its always up-to-date.
  8.     # Sort to keep things purdy
  9.     mod_names = sys.modules.keys()
  10.     mod_names.sort()
  11.     env = os.environ.items()
  12.     env.sort()
  13.     return """
  14. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  15. <html>
  16. <head>
  17.   <title>about:python</title>
  18. </head>
  19. <body>
  20. <h1>about:python</h1>
  21. <p> </p>
  22. <p>Python %(version)s on %(platform)s</p>
  23. <h2>resources</h2>
  24. <p>Visit the <a href="http://developer.mozilla.org/en/docs/PyXPCOM">pyxpcom wiki.</a></p>
  25. <h2>sys.path</h2><p>%(path)s</p><p> </p>
  26. <h2>environment</h2><p>%(environment)s</p><p> </p>
  27. <h2>modules</h2><p>%(modules)s</p><p> </p>
  28.  
  29. </body>
  30. </html>
  31. """ % {
  32.     'version': sys.version,
  33.     'platform': platform.platform(),
  34.     'path': "<br>".join(sys.path),
  35.     'environment': "<br>".join(["%s=%s" % (n,v) for n, v in env]),
  36.     'modules': ", ".join(mod_names),
  37. }
  38.  
  39.  
  40. class AboutPython:
  41.     _com_interfaces_ = components.interfaces.nsIAboutModule
  42.     _reg_contractid_ = '@mozilla.org/network/protocol/about;1?what=python'
  43.     _reg_clsid_ = '{6d5d462e-6de7-4bca-bbc6-c488d481351b}'
  44.     _reg_desc_ = "about:python handler"
  45.  
  46.     def __init__(self):
  47.         pass
  48.  
  49.     def newChannel(self, aURI):
  50.         ioService = components.classes["@mozilla.org/network/io-service;1"] \
  51.             .getService();
  52.  
  53.         istream = components.classes["@mozilla.org/io/string-input-stream;1"] \
  54.             .createInstance()
  55.  
  56.         about = getAbout()
  57.         istream.setData(about, len(about))
  58.  
  59.         channel = components.classes["@mozilla.org/network/input-stream-channel;1"] \
  60.             .createInstance(components.interfaces.nsIInputStreamChannel)
  61.  
  62.         channel.setURI(aURI)
  63.         #channel.contentType = "text/html"
  64.         channel.contentStream = istream
  65.         return channel
  66.  
  67.     def getURIFlags(self, aURI):
  68.         return 0;
  69.